<?php
namespace app\bm\controller;

use think\App;
use think\Controller;
use app\common\model\AuthRule;
use think\Db;
use think\facade\Cache;
use think\facade\Config;
use think\Request;

class Common extends Controller
{
    public function __construct(Request $request)
    {
        parent::__construct();

        // 获取当前用户ID
        define('UID',is_login());

        if( !UID ){// 还没登录 跳转到登录页面
            $this->redirect("/index.php/bm/base/login");
        }

        /* 读取数据库中的配置 */
        $config = Cache::get('DB_CONFIG_DATA'); //读取缓存中的配置
        if(!$config){
            $config	=	api('Config/lists'); //通过接口获取
            Cache::set('DB_CONFIG_DATA',$config); //存入缓存
        }
        Config::set($config);

        // 导航菜单
        $menuList = Db::name('AuthRule')->where('upid',2)->order('id ASC')->select();
        foreach ($menuList as $item => $value) {
            $menuList[$item]['menu'] = Db::name('AuthRule')->where('upid',$value['id'])->order('id DESC')->select();
        }

        // 根据当前action获取上级目录ID


        $this->assign([
            'menuList'=>$menuList
        ]);
    }
}